<?php
/**
 * 好友添加=》修改 =》删除
 */

namespace App\Http\Controllers\Property;

use App\Common\json;
use App\Common\push;
use App\Http\Controllers\Controller;
use App\Libraries\upload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class FriendsController extends Controller{

    private $app_key = '09ae7f39eb877836195b52df';        //待发送的应用程序(appKey)，只能填一个。
    private $master_secret ='28783d0dacf52cfd12d952a6';    //主密码
    private $url = "https://api.jpush.cn/v3/push";      //推送的地址

    private $appios_key = '1aef5ddc66c9bc4e821e84a3';        //待发送的应用程序(appKey)，只能填一个。
    private $masterios_secret ='e0a01a1f2e56db54bf06f3fb';    //主密码
    private $urlios = "https://api.jpush.cn/v3/push";      //推送的地址

    public function userstart($start,$end){
        $data_start = DB::table('friends')
            ->select('user_id', 'phone', 'head', 'nickname', 'sex', 'sign', 'identity',
                'user_address', 'user_village','village_name', 'floor', 'number', 'room', 'oper', 'blacklist','circle_image','user_roomname')
            ->leftjoin('user', 'user.user_id', '=', 'friends.user_end')
            ->leftjoin('village','user.user_village','=','village.village_id')
            ->where('user_start', $start)
            ->where('user_end', $end)
            ->get();
        foreach ($data_start as $key){
            if(empty($key ->oper)){
                $oper     = "0";
            }else{
                $oper     = $key ->oper;
            }
            if(empty($key ->blacklist)){
                $blacklist    = "0";
            }else{
                $blacklist    = $key->blacklist;
            }
            $data    = array(
                'user_id' =>$key ->user_id,
                'phone'   => $key ->phone,
                'head'   => $key ->head,
                'nickname'   => $key ->nickname,
                'sex'   => $key ->sex,
                'sign'   => $key ->sign,
                'identity'   => $key ->identity,
                'province'   => "",
                'city'   => $key ->user_address,

                'district'   => $key->village_name.'-'.$key->user_roomname,
                'village_id'   => $key ->user_village,
                'floor'   => $key ->floor,
                'number'   => $key ->number,
                'room'   => $key ->room,
                'oper'   => $oper,
                'blacklist'   => $blacklist,
                'circle_image' =>$key ->circle_image
            );
        }
        return $data;
    }

    public function userend($start,$end){
        $data_start = DB::table('friends')
            ->select('user_id', 'phone', 'head', 'nickname', 'sex', 'sign', 'identity',
                'user_address', 'user_village','village_name', 'floor', 'number', 'room', 'oper', 'blacklist','circle_image','user_roomname')
            ->leftjoin('user', 'user.user_id', '=', 'friends.user_start')
            ->leftjoin('village','user.user_village','=','village.village_id')
            ->where('user_end', $start)
            ->where('user_start', $end)
            ->get();
        foreach ($data_start as $key){
            if(empty($key ->oper)){
                $oper     = "0";
            }else{
                $oper     = $key ->oper;
            }
            if(empty($key ->blacklist)){
                $blacklist    = "0";
            }else{
                $blacklist    = $key->blacklist;
            }
            $data    = array(
                'user_id' =>$key ->user_id,
                'phone'   => $key ->phone,
                'head'   => $key ->head,
                'nickname'   => $key ->nickname,
                'sex'   => $key ->sex,
                'sign'   => $key ->sign,
                'identity'   => $key ->identity,
                'province'   => "",
                'city'   => $key ->user_address,
                'district'   => $key->village_name.'-'.$key->user_roomname,
                'village_id'   => $key ->user_village,
                'floor'   => $key ->floor,
                'number'   => $key ->number,
                'room'   => $key ->room,
                'oper'   => $oper,
                'blacklist'   => $blacklist,
                'circle_image' =>$key ->circle_image
            );
        }
        return $data;
    }


    public function Info($end){
        $data_start = DB::table('user')
            ->select('user_id', 'phone', 'head', 'nickname', 'sex', 'sign', 'identity',
                'user_address', 'user_village','village_name', 'floor', 'number', 'room','circle_image','user_roomname')
            ->leftjoin('friends', 'user.user_id', '=', 'friends.user_start')
            ->leftjoin('village','user.user_village','=','village.village_id')
            ->where('user_id',$end)
            ->get();
        foreach ($data_start as $key){

            $oper     = "0";


            $blacklist    = "0";

            $data    = array(
                'user_id' =>$key ->user_id,
                'phone'   => $key ->phone,
                'head'   => $key ->head,
                'nickname'   => $key ->nickname,
                'sex'   => $key ->sex,
                'sign'   => $key ->sign,
                'identity'   => $key ->identity,
                'province'   => "",
                'city'   => $key ->user_address,
                'district'   => $key->village_name.'-'.$key->user_roomname,
                'village_id'   => $key ->user_village,
                'floor'   => $key ->floor,
                'number'   => $key ->number,
                'room'   => $key ->room,
                'oper'   => $oper,
                'blacklist'   => $blacklist,
                'circle_image' =>$key ->circle_image
            );
        }
        if($data_start  == true) {
            return json::json('success', '他不是你好友快去加他', $data);
        }else{
            $arr     = (object)array();
            return json::json('failure', '由于网络或者不正当原因得到数据',$arr);
        }
    }

    public function association(Request $request){
        if($request ->isMethod('post')) {
            $user_start     = $request ->input('user_start');
            $user_end       = $request ->input('user_end');
            $data           = DB::table('friends')
                ->where('oper',2)
                ->where(['user_start' =>$user_start,'user_end' =>$user_end])
                ->orwhere(['user_start' =>$user_end,'user_end' =>$user_start])
                ->get();
            foreach ($data as $value) {
                $start = $value->user_start;
                $end = $value->user_end;
                if ($start == $user_start && $end == $user_end) {
                    $dd = $this->userstart($user_start,$user_end);
                }else{
                    $dd = $this ->userend($user_start,$user_end);

                }
            }
            if($data == true){
                return json::json('success', '他不是你好友快去加他', $dd);
            }else{

                return    $info  = $this ->Info($user_end);
                //

            }
        }
    }


    //发送添加好友请求
    public function addfriends(Request $request){
        if($request ->isMethod('post')){
            $arr       = (object)array();
            $user_start   = $request ->input('user_start');
            $user_end     = $request ->input('user_end');
            if(empty($user_start) || empty($user_end)){
                return json::json('100','提交时存在空值','');
            }
            $creation_time    = date('Y-m-d H:i:s');
            $select = DB::table('friends')
                ->select('user_start','user_end')
                ->where('user_end',$user_end)
                ->where('user_start',$user_start)
                ->get();
            if($select  == true){
                return json::json('failure','您已经向该用户发送了添加好友请求',$arr);
            }else{
                $data    = DB::table('friends')
                    ->where('user_end',$user_end)
                    ->insert([
                        'user_start'    =>$user_start,
                        'user_end'      =>$user_end,
                        'oper'     =>1,
                        'creation_time' => $creation_time
                    ]);
                if($data  == true){
                    $end    = DB::table('user') ->select('phone') ->where('user_id',$user_end) ->first();
                    $push   = new push($this ->app_key,$this ->master_secret,$this->url);
                    $push    ->send_pub($end ->phone,'有人请求加你为好友','4');
                    $pushios   = new push($this ->appios_key,$this ->masterios_secret,$this->urlios);
                    $pushios    ->send_pub($end ->phone,'有人请求加你为好友','4');
                    return json::json('success','恭喜您好友请求发送成功',$arr);

                    /*
                                         $pushios   = new push($this ->appios_key,$this ->masterios_secret,$this->urlios);
                                         $pushios    ->send_pub($end ->phone,'有人请求加你为好友','4');*/
                }else{
                    return json::json('failure','好友请求发送失败',$arr);
                }
            }
        }else{
            return json::json('101','提交方式错误','');
        }
    }

    public function SelectFriends(Request $request){
        if($request ->isMethod('post')){
            $Array           = [];
            $user_id          = $request ->input('user_id');
            $data = DB::table('friends')
                ->leftjoin('user','friends.user_start','=','user.user_id')
                ->where('user_end',$user_id)
                ->get();
            foreach ($data as $key){
                $head     = $key ->head;
                $nickname = $key->nickname;
                $sex = $key->sex;
                $sign = $key->sign;
                $identity = $key->identity;
                $user_address = $key->user_address;
                $user_village = $key->user_village;
                $user_roomname = $key->user_roomname;
                /*                $floor = $key->floor;
                                $number = $key->number;
                                $room = $key->room;*/
                if(empty($key ->oper)){
                    $oper   = 0;
                }else {
                    $oper = $key->oper;
                }
                if(empty($key ->blacklist)){
                    $blacklist   = 0;
                }else {
                    $blacklist = $key->blacklist;
                }
                $dd[]        = array(
                    'user_id' =>$key ->user_id,
                    'phone'   => $key ->phone,
                    'head'   => $head,
                    'nickname'   => $nickname,
                    'sex'   => $sex,
                    'sign'   => $sign,
                    'identity'   => $identity,
                    'address'    => $user_address,
                    'village_id'   => $user_village,
                    'user_roomname' =>$user_roomname,

                    /*                    'floor'   => $floor,
                                        'number'   => $number,
                                        'room'   => $room,*/
                    'oper'   => $oper,
                    'blacklist'   => $blacklist,
                );
            }
            if($data  == true){
                return json::json('success','获取添加我好友的数据',$dd);
            }else{
                return json::json('failure','没有添加我好友的数据',$Array);
            }
        }
    }

    //发送添加好友同意 ||把黑名单用户重新添加好友
    public function agreefriends(Request $request){
        if($request ->isMethod('post')){
            $Array     = (object)array();
            $user_id      = $request ->input('user_start');
            $user_end     = $request ->input('user_end');
            if(empty($user_end)){
                return json::json('100','提交时存在空值','');
            }
            $creation_time    = date('Y-m-d H:i:s');
            $data    = DB::table('friends')
                ->where('user_end',$user_id)
                ->where('user_start',$user_end)
                ->update([
                    'oper'    =>2,
                    'update_time'       =>$creation_time
                ]);
            if($data  == true){
                return json::json('success','恭喜您好友同意加您为好友',$Array);
            }else{
                return json::json('failure','添加失败',$Array);
            }
        }else{
            return json::json('101','提交方式错误','');
        }
    }

    //黑名单
    public function blacklistfriends(Request $request){
        if($request ->isMethod('post')){
            $arr  = (object)array();
            $user_start   = $request ->input('user_start');
            $user_end     = $request ->input('user_end');
            if(empty($user_end)){
                return json::json('100','提交时存在空值','');
            }
            $creation_time    = date('Y-m-d H:i:s');
            $data = DB::table('friends')
                ->where(['user_start'=>$user_start,'user_end'=>$user_end])
                ->orwhere(['user_start'=>$user_end,'user_end'=>$user_start])
                ->update([
                    'blacklist' => 1,
                    'update_time' => $creation_time
                ]);
            if ($data == true) {
                return json::json('success', '您已把好友拉入黑名单', $arr);
            } else {
                return json::json('failure', '拉入黑名单失败', $arr);
            }

        }else{
            return json::json('101','提交方式错误','');
        }
    }

    //删除好友
    public function delfriends(Request $request){
        if($request ->isMethod('post')){
            $arr  = (object)array();
            $user_start   = $request ->input('user_start');
            $user_end     = $request ->input('user_end');
            if(empty($user_end)){
                return json::json('100','提交时存在空值','');
            }
            $data    = DB::table('friends')
                ->where(['user_start'=>$user_start,'user_end'=>$user_end])
                ->orwhere(['user_start'=>$user_end,'user_end'=>$user_start])
                ->delete();
            if($data  == true){
                return json::json('success','删除好友成功',$arr);
            }else{
                return json::json('failure','删除好友失败',$arr);
            }
        }else{
            return json::json('101','提交方式错误','');
        }
    }

    public function user_start($id){
        $data_start = DB::table('friends')
            ->select('user_id', 'phone', 'head', 'nickname', 'sex', 'sign', 'identity',
                'user_address', 'user_village', 'floor', 'number', 'room', 'oper', 'blacklist','user_roomname')
            ->leftjoin('user', 'user.user_id', '=', 'friends.user_end')
            ->where('user_start', $id)
            ->where('oper','=',2)
            ->where('blacklist',0)
            ->get();
        return $data_start;
    }

    public function user_end($id){
        $data_start = DB::table('friends')
            ->select('user_id', 'phone', 'head', 'nickname', 'sex', 'sign', 'identity',
                'user_address', 'user_village', 'floor', 'number', 'room', 'oper', 'blacklist','user_roomname')
            ->leftjoin('user', 'user.user_id', '=', 'friends.user_start')
            ->where('user_end', $id)
            ->where('oper','=',2)
            ->where('blacklist',0)
            ->get();
        return $data_start;
    }


    /*public function getfriends(Request $request){
        if ($request->isMethod('post')) {
            $user_start = $request->input('user_start');
            $select = DB::table('friends')
                ->where('user_start', $user_start)
                ->orwhere('user_end', $user_start)
                ->where('oper','=',2)
                ->get();
            if ($select == true) {
                $userstart = $this->user_start($user_start);
                $userend = $this->user_end($user_start);
                $dd = array_merge($userstart, $userend);
                foreach ($dd as $key) {
                    $head = $key->head;
                    $nickname = $key->nickname;
                    $sex = $key->sex;
                    $sign = $key->sign;
                    $identity = $key->identity;
                    $user_address = $key->user_address;
                    $user_village = $key->user_village;
                    $floor = $key->floor;
                    $number = $key->number;
                    $room = $key->room;
                    if (empty($key->oper)) {
                        $oper = 0;
                    } else {
                        $oper = $key->oper;
                    }
                    if (empty($key->blacklist)) {
                        $blacklist = 0;
                    } else {
                        $blacklist = $key->blacklist;
                    }
                    $da[] = array(
                        'user_id' => $key->user_id,
                        'phone' => $key->phone,
                        'head' => $head,
                        'nickname' => $nickname,
                        'sex' => $sex,
                        'sign' => $sign,
                        'identity' => $identity,
                        'address' => $user_address,
                        'village_id' => $user_village,
                        'floor' => $floor,
                        'number' => $number,
                        'room' => $room,
                        'oper' => $oper,
                        'blacklist' => $blacklist,
                    );
                }
                return json::json('success', '获取关联好友', $userend);
            } else {
                return json::json('success', '获取关联好友', []);
            }
        }

    }*/

    public function Submit(Request $request){
        if($request ->isMethod('post')) {
            $value = $request->input('value');
            $user_id = $request->input('user_id');
            if (!is_numeric($value)) {
                return json::json('failure', '查找不到用户信息', []);
            } else {
                $data = DB::select('
                select *, 2 as oper,0 as blacklist from pro_user join pro_village on pro_user.user_village=pro_village.village_id WHERE phone =' . $value . ' AND user_id  in 
	(
		select user_id from (
			(select pro_friends.user_start as user_id, 1 as oper from pro_friends WHERE pro_friends.user_end = ' . $user_id . ' and pro_friends.oper=2 and pro_friends.blacklist=0)
		union 
			( select pro_friends.user_end as user_id, 2 as oper from pro_friends WHERE pro_friends.user_start = ' . $user_id . ' and pro_friends.oper=2 and pro_friends.blacklist=0)
		) 
	as temp_table )

union
select *, 2 as oper,1 as blacklist from pro_user join pro_village on pro_user.user_village=pro_village.village_id WHERE phone =' . $value . ' AND user_id  in 
	(
		select user_id from (
			(select pro_friends.user_start as user_id, 1 as oper from pro_friends WHERE pro_friends.user_end = ' . $user_id . ' and pro_friends.oper=2 and pro_friends.blacklist=1)
		union 
			( select pro_friends.user_end as user_id, 2 as oper from pro_friends WHERE pro_friends.user_start = ' . $user_id . ' and pro_friends.oper=2 and pro_friends.blacklist=1)
		) 
	as temp_table )

union
select *, 1 as oper,0 as blacklist from pro_user join pro_village on pro_user.user_village=pro_village.village_id WHERE  phone =' . $value . ' AND user_id  in 
	(
		select user_id from (
			(select pro_friends.user_start as user_id, 1 as oper from pro_friends WHERE pro_friends.user_end = ' . $user_id . ' and pro_friends.oper=1)
		union 
			( select pro_friends.user_end as user_id, 2 as oper from pro_friends WHERE pro_friends.user_start = ' . $user_id . ' and pro_friends.oper=1)
		) 
	as temp_table )

union 

select *,  0 as oper,0 as blacklist from pro_user join pro_village on pro_user.user_village=pro_village.village_id WHERE phone =' . $value . ' AND  user_id not in 
	(
		select user_id from (
			(select pro_friends.user_start as user_id, 1 as oper from pro_friends WHERE pro_friends.user_end = ' . $user_id . '  )
		union 
			( select pro_friends.user_end as user_id, 2 as oper from pro_friends WHERE pro_friends.user_start = ' . $user_id . ' )
		) 
	as temp_table )
            ');

                foreach ($data as $key) {
                    $id = $key->user_id;
                    if (empty($key->oper)) {
                        $oper = "0";
                    } else {
                        $oper = $key->oper;
                    }
                    if (empty($key->blacklist)) {
                        $blacklist = "0";
                    } else {
                        $blacklist = $key->blacklist;
                    }
                    $dd[$id]['user_id'] = $key->user_id;
                    $dd[$id]['phone'] = $key->phone;
                    $dd[$id]['head'] = $key->head;
                    $dd[$id]['nickname'] = $key->nickname;
                    $dd[$id]['sex'] = $key->sex;
                    $dd[$id]['sign'] = $key->sign;
                    $dd[$id]['identity'] = $key->identity;
                    $dd[$id]['user_address'] = $key->user_address;
                    $dd[$id]['user_village'] = $key->user_village;
                    $dd[$id]['user_roomname'] = $key->user_roomname;
                    /*                    $dd[$id]['user_roomname'] = $key->floor;
                                        $dd[$id]['number'] = $key->number;
                                        $dd[$id]['room'] = $key->room;*/
                    $dd[$id]['oper'] = $oper;
                    $dd[$id]['blacklist'] = $blacklist;
                    $da = array_values($dd);
                }
                if ($data == true) {
                    return json::json('success', '获取查询信息成功', $da);
                } else {
                    return json::json('failure', '查找不到用户信息', []);
                }
            }
        }
    }

    public function SubmitFriends(Request $request,$type){
        if($request ->isMethod('post')){
            $village         = $request ->input('village_id');
            $user_id           = $request ->input('user_id');
            if(empty($village)){
                return json::json('failure', '查找不到用户信息', []);
            }
            if(empty($user_id)){
                return json::json('failure', '查找不到用户信息', []);
            }
            if($type ==1) {
                $data         = DB::select('select *,  0 as oper,0 as blacklist from `pro_user` inner join `pro_village` on `pro_user`.`user_village` =
`pro_village`.`village_id` where `user_village` = '.$village.' and pro_user.user_id !='.$user_id.' and
user_id  not in 
	(
		select user_id from (
			(select pro_friends.user_start as user_id, 1 as oper from pro_friends WHERE pro_friends.user_end = '.$user_id.')
		union 
			( select pro_friends.user_end as user_id, 2 as oper from pro_friends WHERE pro_friends.user_start = '.$user_id.')
		) 
	as temp_table )
');
                $data1  = DB::select('select *,  1 as oper,0 as blacklist from `pro_user` inner join `pro_village` on `pro_user`.`user_village` = `pro_village`.`village_id` where `user_village` = '.$village.' and pro_user.user_id !='.$user_id.' and
user_id   in 
	(
		select user_id from (
			(select pro_friends.user_start as user_id, 1 as oper from pro_friends WHERE pro_friends.user_end = '.$user_id.' and pro_friends.oper=1)
		union 
			( select pro_friends.user_end as user_id, 2 as oper from pro_friends WHERE pro_friends.user_start = '.$user_id.' and pro_friends.oper=1)
		) 
	as temp_table )
');
                if(empty($data)){
                    $start   = array();
                }else{
                    $start   = $data;
                }
                if(empty($data1)){
                    $end   = array();
                }else{
                    $end   = $data1;
                }
                $daa  = array_merge($end,$start);
                if(empty($daa)){
                    return json::json('failure', '查找不到用户信息', []);
                }else {
                    foreach ($daa as $key) {
                        $id = $key->user_id;
                        if ($key->oper == 0) {
                            $oper = 0;
                        } else {
                            $oper = $key->oper;
                        }
                        if ($key->blacklist == 0) {
                            $blacklist = 0;
                        } else {
                            $blacklist = $key->blacklist;
                        }
                        $dd[$id]['user_id'] = $key->user_id;
                        $dd[$id]['phone'] = $key->phone;
                        $dd[$id]['head'] = $key->head;
                        $dd[$id]['nickname'] = $key->nickname;
                        $dd[$id]['sex'] = $key->sex;
                        $dd[$id]['sign'] = $key->sign;
                        $dd[$id]['identity'] = $key->identity;
                        $dd[$id]['user_address'] = $key->user_address;
                        $dd[$id]['user_village'] = $key->user_village;
                        $dd[$id]['user_roomname'] = $key->user_roomname;
                        /*                        $dd[$id]['floor'] = $key->floor;
                                                $dd[$id]['number'] = $key->number;
                                                $dd[$id]['room'] = $key->room;*/
                        $dd[$id]['oper'] = $oper;
                        $dd[$id]['blacklist'] = $blacklist;
                    }
                    if(empty($dd)){
                        $sd  = array();
                    }else{
                        $sum  = count($dd);
                        if($sum ==1){
                            $sd = array_values($dd);
                            return json::json('success', '获取查询信息成功', $sd);
                        }else {
                            $sd = array_values($dd);
                            $temp = array_rand($sd, $sum);
                        }
                    }
                    if (!empty($temp)) {
                        foreach ($temp as $val) {
                            $data_last[] = $sd[$val];
                        }
                    } else {
                        return json::json('failure', '查找不到用户信息', []);
                    }

                    if (!empty($daa)) {
                        return json::json('success', '获取查询信息成功', $data_last);
                    } else {
                        return json::json('failure', '查找不到用户信息', []);
                    }
                }
            }else {
                $data = DB::select('select *,  0 as oper,0 as blacklist from `pro_user` left join `pro_village` on `pro_user`.`user_village` = 
`pro_village`.`village_id` where `user_village` != ' . $village . '  and
user_id  not in 
	(
		select user_id from (
			(select pro_friends.user_start as user_id, 1 as oper from pro_friends WHERE pro_friends.user_end = ' . $user_id . ')
		union 
			( select pro_friends.user_end as user_id, 2 as oper from pro_friends WHERE pro_friends.user_start = ' . $user_id . ')
		) 
	as temp_table )

');
                $data1 = DB::select('select *,  1 as oper,0 as blacklist from `pro_user` inner join `pro_village` on `pro_user`.`user_village` = `pro_village`.`village_id` where `user_village` != ' . $village . ' and pro_user.user_id !=' . $user_id . ' and
user_id    in 
	(
		select user_id from (
			(select pro_friends.user_start as user_id, 1 as oper from pro_friends WHERE pro_friends.user_end = ' . $user_id . ' and pro_friends.oper=1)
		union 
			( select pro_friends.user_end as user_id, 2 as oper from pro_friends WHERE pro_friends.user_start = ' . $user_id . ' and pro_friends.oper=1)
		) 
	as temp_table )

');
                if(empty($data)){
                    $start   = array();
                }else{
                    $start   = $data;
                }
                if(empty($data1)){
                    $end   = array();
                }else{
                    $end   = $data1;
                }
                $daa = array_merge($end, $start);
                if (empty($daa)) {
                    return json::json('failure', '查找不到用户信息', []);
                } else {
                    foreach ($daa as $key) {
                        $id = $key->user_id;
                        if ($key->oper == 0) {
                            $oper = 0;
                        } else {
                            $oper = $key->oper;
                        }
                        if ($key->blacklist == 0) {
                            $blacklist = 0;
                        } else {
                            $blacklist = $key->blacklist;
                        }
                        $dd[$id]['user_id'] = $key->user_id;
                        $dd[$id]['phone'] = $key->phone;
                        $dd[$id]['head'] = $key->head;
                        $dd[$id]['nickname'] = $key->nickname;
                        $dd[$id]['sex'] = $key->sex;
                        $dd[$id]['sign'] = $key->sign;
                        $dd[$id]['identity'] = $key->identity;
                        $dd[$id]['user_address'] = $key->user_address;
                        $dd[$id]['user_village'] = $key->user_village;
                        $dd[$id]['user_roomname'] = $key->user_roomname;
                        /*                        $dd[$id]['floor'] = $key->floor;
                                                $dd[$id]['number'] = $key->number;
                                                $dd[$id]['room'] = $key->room;*/
                        $dd[$id]['oper'] = $oper;
                        $dd[$id]['blacklist'] = $blacklist;
                        //$da   = array_values($dd);
                    }

                    if(empty($dd)){
                        $sd  = array();
                    }else{
                        $sum  = count($dd);
                        if($sum ==1){
                            $sd = array_values($dd);
                            return json::json('success', '获取查询信息成功', $sd);
                        }else {
                            $sd = array_values($dd);
                            $temp = array_rand($sd, $sum);
                        }
                    }

                    if (!empty($temp)) {
                        foreach ($temp as $val) {
                            $data_last[] = $sd[$val];
                        }
                    } else {
                        return json::json('failure', '查找不到用户信息', []);
                    }

                    if (!empty($daa)) {
                        return json::json('success', '获取查询信息成功', $data_last);
                    } else {
                        return json::json('failure', '查找不到用户信息', []);
                    }

                }

            }
        }
    }

    public function group(Request $request){
        if($request ->isMethod('post')){
            $phone          = $request ->input('phone');
            $array_ids = explode(',',$phone);
            $result = array();
            foreach($array_ids as $k =>$v){
                $res = DB::table('user')->select('user_id','phone','head','nickname')->where('phone','=',$v)->first();
                $result[] = $res;
            }
            if(! empty($result)){
                return json::json('success','获取群聊信息成功',$result);
            }else{
                return json::json('failure','获取群聊信息失败',[]);
            }
        }
    }




}